package com.banmao.algorithm.No101To200.No151;

/**
 *  偷鸡的方法，效率极低
 */
public class Solution1 {

    public String reverseWords(String s) {

        // 偷鸡
        String[] split = s.split("\\s+");

        StringBuffer sb = new StringBuffer();
        for (int i = split.length -1; i >= 0; i--) {
            if(!"".equals(split[i])) {
                sb.append(split[i]);
                if(i != 0) {
                    sb.append(" ");
                }
            } else {
                sb.deleteCharAt(sb.length() - 1);
            }
        }

        return sb.toString();
    }


}
